//引入css
require("../css/sport.less")


document.ready(function () {
    const BASE_URL = 'http://139.9.177.51:8099' // 接口请求的 URL

    //动态添加页尾
    window.$utils.creatFooter(1)

    let userId = JSON.parse(window.localStorage.getItem("user")).userId
    // console.log(userId);
    window.$http.get("/sports/courseList?id=" + userId, function (res) {
        console.log(res.data);
        let latest = res.data.find(function (item) {
            return item.latest == 1
        })
        // console.log(latest);
        //动态添加最新课程
        let newCourse = document.querySelector(".newCourse")
        newCourse.innerHTML = `
    <a href="./course-details.html?id=${res.data[0].courseId}" class="newCourse">
    <h5>最新课程</h5>
    <div class="newCourse-content">
    <div class="imgbox" style="background-image:url(${BASE_URL + latest.imgurl})"></div>
    <div class="describe">
    <h6>${latest.name}</h6>
    <p>${latest.desc}</p>
    </div>
    </div>
    </a>
    `
        //动态添加旧课程
        let arr = res.data.filter(function (item) {
            return item.latest != 1
        })
        console.log(arr);
        let courseAll = document.querySelector(".courseAll")
        courseAll.innerHTML = `<h6>课程</h6>`
        arr.forEach(function (v) {
            // console.log(v);
            courseAll.innerHTML += `
        <a class="course" href="./course-details.html?id=${v.courseId}">
        <div class="ibox" style="background-image: url(${BASE_URL + v.imgurl});"></div>
        <h6>${v.name}</h6>
        <p>${v.desc}</p>
        </a>
        `
        })
    })

})